home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
CC_C
/
1116.ZIP
/
TOOLKIT.ARC
/
_FILES.H
< prev
next >
Wrap
Text File
|
1979-12-31
|
8KB
|
188 lines
/* _FILES.H written by Wayne Pearson for Small C:PC
hexprint() writes a new file, with extension .HEX, that contains the
hexadecimal ASCII code values of the file to hexprint.
fprintf() writes numbers in readable, multiple-digit form to ASCII files.
Also, fprintf() writes strings to file. Embedded line feeds
are allowed in these strings.
Valid function calls:
hexprint(myfile); creates new *.HEX file hexprint dump of myfile
hexprint("a:data.dat"); creates A:DATA.HEX as the hexprint dump
fprintf("%d",65,fptr); writes the decimal integer 65 to file
fprintf("%h",65,fptr); writes the hexadecimal integer 41 to file
fprintf("%o",65,fptr); writes the octal integer 101 to file
fprintf("%b",65,fptr); writes the binary integer 1000001 to file
fprintf("\nHello\n\nworld\n",0,fptr);
writes string with embedded line feeds to file
*/
hexprint(ha_name)
char ha_name[];
{
int hexf_16,hexf_1,*ha_ptr,*hf_ptr,ha_pos,ln_cntr,chk_lcv;
char hf_name[14],mn_chr,hpf_2h,hf_chr16[255],hf_chr_1[255];
ha_ptr = fopen(ha_name,"r"); /* one file open at a time */
ha_pos = ln_cntr = chk_lcv = 0; hpf_2h = 32; mn_chr = 'a';
while(mn_chr != 0) { mn_chr = ha_name[ln_cntr]; ++ln_cntr; }
while((chk_lcv <= ln_cntr)&(ha_pos ==0))
{
mn_chr = ha_name[chk_lcv]; ++chk_lcv;
if(mn_chr == '.') ha_pos = chk_lcv;
}
if(ha_pos > 0)
{
chk_lcv = 1;
while(chk_lcv <= ha_pos)
{
hf_name[chk_lcv - 1] = ha_name[chk_lcv - 1];
++chk_lcv;
}
hf_name[chk_lcv - 1] = 'H'; ++chk_lcv;
hf_name[chk_lcv - 1] = 'E'; ++chk_lcv;
hf_name[chk_lcv - 1] = 'X'; ++chk_lcv;
hf_name[chk_lcv - 1] = 0; /* ASCIIZ */
}
else
{
chk_lcv = 1;
while(chk_lcv < ln_cntr)
{
hf_name[chk_lcv - 1] = ha_name[chk_lcv - 1];
++chk_lcv;
}
hf_name[chk_lcv - 1] = '.'; ++chk_lcv;
hf_name[chk_lcv - 1] = 'H'; ++chk_lcv;
hf_name[chk_lcv - 1] = 'E'; ++chk_lcv;
hf_name[chk_lcv - 1] = 'X'; ++chk_lcv;
hf_name[chk_lcv - 1] = 0; /* ASCIIZ */
}
chk_lcv = 0; hpf_2h = 1;
while((hpf_2h != 0)&(chk_lcv < 255))
{
hpf_2h = getc(ha_ptr);
if(hpf_2h >= 16)
{
hexf_16 = hpf_2h / 16;
hexf_1 = hpf_2h - hexf_16 * 16;
if(((hexf_16 * 16) % 16) >= 8) --hexf_1;
}
else { hexf_16 = 0; hexf_1 = hpf_2h; }
if(hexf_16 > 9) hexf_16 = hexf_16 + 7;
if(hexf_1 > 9) hexf_1 = hexf_1 + 7;
hexf_16 = hexf_16 + 48; hexf_1 = hexf_1 + 48;
hf_chr16[chk_lcv] = hexf_16;
hf_chr_1[chk_lcv] = hexf_1; ++chk_lcv;
}
fclose(ha_ptr);
hf_ptr = fopen(hf_name,"w");
ln_cntr = 0; hexf_1 = 1;
while(ln_cntr < chk_lcv)
{
hpf_2h = hf_chr16[ln_cntr]; putc(hpf_2h,hf_ptr);
hpf_2h = hf_chr_1[ln_cntr]; putc(hpf_2h,hf_ptr);
putc(32,hf_ptr);
hexf_16 = hf_chr16[ln_cntr];
if(((hexf_16 == '0')&(hpf_2h == 'D'))|((hexf_1 % 25) ==0))
{ putc(13,hf_ptr); hexf_1 = 1; }
++ln_cntr; ++hexf_1;
}
fclose(hf_ptr);
}
fprintf(ff_1,ff_2d,f_p)
char ff_1[]; int ff_2d,*f_p;
{
if((ff_1[0] == '%')&(ff_1[1] == 'd')) f_dec(10,ff_2d,f_p);
else if((ff_1[0] == '%')&(ff_1[1] == 'h')) f_hex(ff_2d,f_p);
else if((ff_1[0] == '%')&(ff_1[1] == 'o')) f_dec(8,ff_2d,f_p);
else if((ff_1[0] == '%')&(ff_1[1] == 'b')) f_bin(ff_2d,f_p);
else f_str(ff_1,f_p);
}
f_dec(fase_n,ff_2,f_pd)
int fase_n, ff_2, *f_pd;
{
int fec_100, fec_10, fec_1, fase_nn;
fase_nn = fase_n * fase_n;
if(ff_2 >= fase_nn) fec_100 = ff_2 / fase_nn; else fec_100 = 0;
if(ff_2 >= fase_n)
{
fec_10 = ff_2 - fec_100 * fase_nn;
fec_10 = fec_10 / fase_n;
}
else fec_10 = 0;
if(ff_2 >= fase_nn)
{
fec_1 = ff_2 - fec_100 * fase_nn - fec_10 * fase_n;
if(((fec_100 * fase_nn) % fase_nn) >= (fase_nn/2 -1))--fec_1;
if(((fec_10 * fase_n) % fase_n) >= (fase_n / 2 - 1 ))--fec_1;
}
if((ff_2 < fase_nn)&(ff_2 >= fase_n))
{
fec_1 = ff_2 -fec_10 * fase_n;
if(((fec_10 * fase_n) % fase_n) >= (fase_n / 2 - 1 ))--fec_1;
}
if(ff_2 < fase_n) fec_1 = ff_2;
fec_100 = fec_100 + 48; fec_10 = fec_10 + 48; fec_1 = fec_1 + 48;
if(fec_100 > 48) putc(fec_100,f_pd);
if(((fec_100 > 48)&(fec_10 >= 48))|(fec_10 > 48)) putc(fec_10,f_pd);
putc(fec_1,f_pd);
}
f_hex(ff_2h,f_ph)
int ff_2h,*f_ph;
{
int fex_16, fex_1;
if(ff_2h >= 16)
{
fex_16 = ff_2h / 16; fex_1 = ff_2h - fex_16 * 16;
if(((fex_16 * 16) % 16) >= 8) --fex_1;
}
else { fex_16 = 0; fex_1 = ff_2h; }
if(fex_16 > 9) fex_16 = fex_16 + 7;
if(fex_1 > 9) fex_1 = fex_1 + 7;
fex_16 = fex_16 + 48; fex_1 = fex_1 + 48;
if(fex_16 > 48) putc(fex_16,f_ph); putc(fex_1,f_ph);
}
f_bin(f_2,f_pb)
int f_2,*f_pb;
{
int fin_8,fin_7,fin_6,fin_5,fin_4,fin_3,fin_2,fin_1,fin_mod;
fin_8 =fin_7 =fin_6 =fin_5 =fin_4 =fin_3 =fin_2 =fin_1 =0;
fin_mod = f_2 / 128; if(fin_mod > 0) fin_8 = 1;
fin_mod = f_2 / 64; fin_mod = fin_mod % 2;
if(fin_mod > 0) fin_7 = 1;
fin_mod = f_2 / 32; fin_mod = fin_mod % 2;
if(fin_mod > 0) fin_6 = 1;
fin_mod = f_2 / 16; fin_mod = fin_mod % 2;
if(fin_mod > 0) fin_5 = 1;
fin_mod = f_2 / 8; fin_mod = fin_mod % 2;
if(fin_mod > 0) fin_4 = 1;
fin_mod = f_2 / 4; fin_mod = fin_mod % 2;
if(fin_mod > 0) fin_3 = 1;
fin_mod = f_2 / 2; fin_mod = fin_mod % 2;
if(fin_mod > 0) fin_2 = 1;
fin_mod = f_2 % 2; if(fin_mod > 0) fin_1 = 1;
if(f_2 > 255) fin_8 = 40;
putc(fin_8+48,f_pb); putc(fin_7+48,f_pb); putc(fin_6+48,f_pb);
putc(fin_5+48,f_pb); putc(fin_4+48,f_pb); putc(fin_3+48,f_pb);
putc(fin_2+48,f_pb); putc(fin_1+48,f_pb);
}
f_str(ftr_nm,f_ps)
char ftr_nm[],*f_ps;
{
char fhr_str,ftr_end; int ftr_lcv; ftr_end='a'; ftr_lcv = 0;
while(ftr_end != 0)
{
ftr_end = ftr_nm[ftr_lcv];
if(ftr_end == '\') {++ftr_lcv; putc(13,f_ps);}
else {fhr_str = ftr_nm[ftr_lcv]; putc(fhr_str,f_ps);}
++ftr_lcv;
}
}